/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.updateAcc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Bach
 */
public class CheckAccAdmin {

    public static boolean checkexits(UpdateAccAdminForm u, Connection cnn) {
        boolean re = false;
        PreparedStatement ps;
        String sql = " SELECT [User_Name],[User_Email]"
                + "  FROM [Matrimony].[dbo].[Accounts]"
                + "  where Account_Id=? and User_Email=? and User_Password=? and [Account_Role]='admin'";
        ResultSet rs = null;
        String email = null;
        String pass = null;
        int accId = 0;
        if (u != null) {
            email = u.getEmail();
            accId = Integer.parseInt(u.getAccId());
            pass = u.getOldpass();
            accId = Integer.parseInt(u.getAccId());
            try {
                ps = cnn.prepareStatement(sql);
                ps.setInt(1, accId);
                ps.setString(2, email);
                ps.setString(3, pass);
                rs = ps.executeQuery();
                if (rs.next()) {
                    re = true;
                } else {
                    re = false;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return re;
    }
}
